#ifndef DOWNLOADER_H
#define DOWNLOADER_H

#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include "modelversion.h"

namespace ns_yht
{

    class /*UPDATEUTIL_EXPORT*/ Downloader : public QObject
    {
        Q_OBJECT

    public:
        Downloader(QNetworkAccessManager *manage, const QString &appDir, bool isBackup = false);

        void start(const QString &fileName, const QString &url);

    public slots:
        void onFinished();
        void onDownloadProgress(qint64 a, qint64 b);
        void onDownloadReadyRead();

    signals:
        void finished(bool isSucceed);
        void downloadProgress(qint64 a, qint64 b);

    private:
        QNetworkAccessManager *m_manage;
        QString m_appDir;
        QFile *m_file;
        QNetworkReply *m_reply;
        QNetworkRequest m_request;

        QString m_remoteFileName;

        bool m_isRunning;
        bool m_isBackup; // 是否需要备份
    };

}
#endif // DOWNLOADER_H
